package com.jin.jpa.wrapper;

import com.jin.jpa.wrapper.expression.WhereOpExpression;
import com.jin.jpa.wrapper.support.FieldFunction;
import com.jin.jpa.wrapper.support.IWrapper;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yuanxiuyao
 * @Date: 2024/1/8 16:31
 * @PackageName: org.example.jpa.wrapper.expression
 * @Version 1.0
 */
public interface AbstractWhereWrapper<T> extends IWrapper<T> {

    List<WhereOpExpression> whereOpExpressions = new ArrayList<>();

    default WhereOpExpression<T> and(){
        WhereOpExpression<T> whereExpressionOp = new WhereOpExpression(WhereOpExpression.ExpressionOp.AND, this);
        whereOpExpressions.add(whereExpressionOp);
        return whereExpressionOp;
    }

    default WhereOpExpression<T> or(){
        WhereOpExpression<T> whereExpressionOp = new WhereOpExpression(WhereOpExpression.ExpressionOp.OR, this);
        whereOpExpressions.add(whereExpressionOp);
        return whereExpressionOp;
    }

    default WhereOpExpression<T> and(FieldFunction<T, ?> expression, Object value){
        WhereOpExpression<T> whereExpressionOp = new WhereOpExpression(WhereOpExpression.ExpressionOp.AND, this);
        whereExpressionOp.equal(expression, value);
        whereOpExpressions.add(whereExpressionOp);
        return whereExpressionOp;
    }

    default WhereOpExpression<T> or(FieldFunction<T, ?> expression, Object value){
        WhereOpExpression<T> whereExpressionOp = new WhereOpExpression(WhereOpExpression.ExpressionOp.OR, this);
        whereExpressionOp.equal(expression, value);
        whereOpExpressions.add(whereExpressionOp);
        return whereExpressionOp;
    }

    default WhereOpExpression<T> andNull(FieldFunction<T, ?> expression){
        WhereOpExpression<T> whereExpressionOp = new WhereOpExpression(WhereOpExpression.ExpressionOp.AND, this);
        whereExpressionOp.isNull(expression);
        whereOpExpressions.add(whereExpressionOp);
        return whereExpressionOp;
    }

    default WhereOpExpression<T> andNotNull(FieldFunction<T, ?> expression){
        WhereOpExpression<T> whereExpressionOp = new WhereOpExpression(WhereOpExpression.ExpressionOp.AND, this);
        whereExpressionOp.isNotNull(expression);
        whereOpExpressions.add(whereExpressionOp);
        return whereExpressionOp;
    }

    default WhereOpExpression<T> orNull(FieldFunction<T, ?> expression){
        WhereOpExpression<T> whereExpressionOp = new WhereOpExpression(WhereOpExpression.ExpressionOp.OR, this);
        whereExpressionOp.isNull(expression);
        whereOpExpressions.add(whereExpressionOp);
        return whereExpressionOp;
    }

    default WhereOpExpression<T> orNotNull(FieldFunction<T, ?> expression){
        WhereOpExpression<T> whereExpressionOp = new WhereOpExpression(WhereOpExpression.ExpressionOp.OR, this);
        whereExpressionOp.isNotNull(expression);
        whereOpExpressions.add(whereExpressionOp);
        return whereExpressionOp;
    }

    default WhereOpExpression<T> orBetween(FieldFunction<T, ?> expression, Object value1, Object value2){
        WhereOpExpression<T> whereExpressionOp = new WhereOpExpression(WhereOpExpression.ExpressionOp.OR, this);
        whereExpressionOp.between(expression, value1, value2);
        whereOpExpressions.add(whereExpressionOp);
        return whereExpressionOp;
    }

    default WhereOpExpression<T> andBetween(FieldFunction<T, ?> expression, Object value1, Object value2){
        WhereOpExpression<T> whereExpressionOp = new WhereOpExpression(WhereOpExpression.ExpressionOp.AND, this);
        whereExpressionOp.between(expression, value1, value2);
        whereOpExpressions.add(whereExpressionOp);
        return whereExpressionOp;
    }
}
